﻿<Window x:Class="Lucy.Editor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:Lucy.Editor.Converters" Title="MainWindow" 
        Height="350" 
        Width="525">
    <Window.Resources>
        <ResourceDictionary>
            
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Views/DocumentViews.xaml" />
            </ResourceDictionary.MergedDictionaries>
            
            <ContextMenu 
                x:Key="ViewModelContextMenu"
                ItemsSource="{Binding ContextMenuCommands}">
                <ContextMenu.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Command" Value="{Binding}" />
                    </Style>
                </ContextMenu.ItemContainerStyle>
                <ContextMenu.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" />
                    </DataTemplate>
                </ContextMenu.ItemTemplate>
            </ContextMenu>
            
            <HierarchicalDataTemplate 
                x:Key="TreeViewItemTemplate"
                ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal" ContextMenu="{StaticResource ViewModelContextMenu}">
                    <Image Source="{Binding Icon}" Width="16" Height="16" />
                    <TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
                </StackPanel>
            </HierarchicalDataTemplate>

            <Style x:Key="ViewModelTreeViewItemContainerStyle" TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
             </Style>
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <Menu>
            <MenuItem Header="Datei">
                <MenuItem Header="Neues Projekt" Command="{Binding CreateProjectCommand}" />
                <MenuItem Header="Projekt öffnen" />
                <Separator />
                <MenuItem Header="Beenden" Command="{Binding CloseCommand}" />
            </MenuItem>
            <MenuItem Header="Bearbeiten" />
            <MenuItem Header="Ansicht" />
            <MenuItem Header="Info" />
        </Menu>


        <Grid Grid.Row="1" DataContext="{Binding Project, Converter={x:Static Converters:DebugConverter.Instance}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                
                    <TreeView 
                        ItemContainerStyle="{StaticResource ViewModelTreeViewItemContainerStyle}"
                        DataContext="{Binding RootAssetTreeViewItem}" 
                        ItemsSource="{Binding Children}" 
                        ItemTemplate="{StaticResource TreeViewItemTemplate}" />

                    <TreeView 
                        Grid.Row="1"
                    ItemContainerStyle="{StaticResource ViewModelTreeViewItemContainerStyle}"
                    DataContext="{Binding RootProjectTreeViewItem}" 
                    ItemsSource="{Binding Children}" 
                    ItemTemplate="{StaticResource TreeViewItemTemplate}" />

            </Grid>

            <TabControl 
                Grid.Column="1" 
                ItemsSource="{Binding Documents}">
                <TabControl.ItemContainerStyle>
                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="Header" Value="{Binding Name}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                    </Style>
                </TabControl.ItemContainerStyle>
            </TabControl>
        </Grid>

    </Grid>
    
</Window>
